//
//  SERegistrationDoctorView.swift
//  SmartEyeForPatient
//
//  Created by qdsg on 2021/4/21.
//

import UIKit

protocol SERegistrationDoctorViewDelegate: NSObjectProtocol {
    func registrationDoctorViewTapAction(doctorModel: SERegistrationDoctorModel)
}

class SERegistrationDoctorView: UIView {

    @IBOutlet weak var avatorImgView: UIImageView! {
        didSet {
            avatorImgView.layer.cornerRadius = avatorImgView.frame.size.height / 2.0
            avatorImgView.layer.masksToBounds = true
        }
    }
    @IBOutlet weak var nameLabel: UILabel!
    @IBOutlet weak var jobTitleLabel: UILabel!
    @IBOutlet weak var goodAtLabel: UILabel!
    @IBOutlet weak var arrowImgView: UIImageView!

    weak var deleagte: SERegistrationDoctorViewDelegate?
    var doctorModel = SERegistrationDoctorModel()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
        setupUI()
    }

    func updateView(model: SERegistrationDoctorModel) {
        self.doctorModel = model
        avatorImgView.kf.setAvatarImage(urlString: model.picUrl)
        nameLabel.text = model.doctorName
        jobTitleLabel.text = model.jobTitle
        goodAtLabel.text = model.goodAt
        arrowImgView.isHidden = model.inquirydocId.isEmpty
    }

    func setupUI() {
        loadNib()
        addTap()
    }

    private func addTap() {
        let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
        addGestureRecognizer(tap)
    }

    @objc private func tapAction() {
        deleagte?.registrationDoctorViewTapAction(doctorModel: self.doctorModel)
    }

    func loadNib() {
        let view = UINib.init(nibName: String(describing: type(of: self)), bundle: nil).instantiate(withOwner: self, options: nil).last as! UIView
        view.frame = bounds
        addSubview(view)
    }

}
